package com.app.service.impl;

import cn.hutool.core.util.StrUtil;
import com.app.mapper.EntrepreneursUserMapper;
import com.app.model.EntrepreneursUserModel;
import com.app.service.EntrepreneursUserService;
import com.app.vo.EntrepreneursUserVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创业用户绑定
 *
 * @author 16693103420
 * @since 2024-02-02
 */
@Service
public class EntrepreneursUserServiceImpl extends ServiceImpl<EntrepreneursUserMapper, EntrepreneursUserModel> implements EntrepreneursUserService {
    @Autowired
    private EntrepreneursUserMapper entrepreneursUserMapper;

    @Override
    public EntrepreneursUserVo getEntrepreneursUserList(Integer page, Integer limit, Integer id, String keyword) {
        Page<EntrepreneursUserModel> page1 = new Page<>(page, limit);
        QueryWrapper<EntrepreneursUserModel> qw = new QueryWrapper<>();
        if (StrUtil.isNotBlank(keyword)) {
            qw.like("user_name", keyword).or().like("phone", keyword);
        }
        qw.eq("entrepreneurs_id", id);
        qw.orderByDesc("create_time");
        Page<EntrepreneursUserModel> entrepreneursUserPage = entrepreneursUserMapper.selectPage(page1, qw);
        List<EntrepreneursUserModel> entrepreneursUserList = entrepreneursUserPage.getRecords();
        long count = entrepreneursUserPage.getTotal();
        EntrepreneursUserVo entrepreneursUserVo = new EntrepreneursUserVo();
        entrepreneursUserVo.setList(entrepreneursUserList);
        entrepreneursUserVo.setCount((int) count);
        return entrepreneursUserVo;
    }
}
